﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EnhancedWebControls;

namespace EwcControlTest
{
    public partial class MultiSelectDropDowns : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lblResults1.Text =null;
            lblResults1.Visible = false;
            if (!Page.IsPostBack)
            {
                MultiSelectDropDown2.SelectedValue = "1";
                MultiSelectDropDown2.SelectedValue = "3";
                MultiSelectDropDown2.DataSource = GetItems();
                MultiSelectDropDown2.DataTextField = "x";
                MultiSelectDropDown2.DataValueField = "y";
                MultiSelectDropDown2.DataBind();

                MultiSelectDropDown3.DataSource = GetItems();
                MultiSelectDropDown3.DataTextField = "x";
                MultiSelectDropDown3.DataValueField = "y";
                MultiSelectDropDown3.SelectedValue = "3";
                MultiSelectDropDown3.SelectedValue = "5";
                MultiSelectDropDown3.DataBind();

                MultiSelectDropDown5.DataSource = GetItems();
                MultiSelectDropDown5.DataTextField = "x";
                MultiSelectDropDown5.DataValueField = "y";
                MultiSelectDropDown5.DataBind();
                MultiSelectDropDown5.SelectedValue = "2";
            }
        }
        private object GetItems()
        {
            return new[] { new { x = "Test Item 1", y = 1 }
                , new { x = "Test Item 2", y = 2 }
                , new { x = "Test Item 3", y = 3 }
                , new { x = "Test Item 4", y = 4 }
                , new { x = "Test Item 5", y = 5 } 
                , new { x = "Test Item 6", y = 6 }
                , new { x = "Test Item 7", y = 7 } 
                , new { x = "Test Item 8", y = 8 }
                , new { x = "Test Item 9", y = 9 }
                , new { x = "Test Item 10", y = 10 } 
                , new { x = "Test Item 11", y = 11 }
                , new { x = "Test Item 12", y = 12 } 
                , new { x = "Test Item 13", y = 13 }
                , new { x = "Test Item 14", y = 14 }
                , new { x = "Test Item 15", y = 15 } 
                , new { x = "Test Item 16", y = 16 }
                , new { x = "Test Item 17", y = 17 } 
                , new { x = "Test Item 18", y = 18 }  };
        }
        protected void ddlMultiSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            string msg = string.Empty;
            foreach (string s in ((MultiSelectDropDown)sender).SelectedValues)
            {
                if (msg.Length > 0)
                    msg += ", ";
                msg += s;
            }
            lblResults1.Text = "You Selected: " + msg;
            lblResults1.Visible = true;
        }
    }
}